﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassesForFtpCrawler
{
    public class ConnectionStringUser
    {
        private string ConnectionString = string.Empty;

        public override string ToString()
        {
            return this.ConnectionString;
        }

        public ConnectionStringUser(string ConnectionString)
        {
            this.ConnectionString = ConnectionString;
        }
        public String DataSource
        {
            get
            {
                return this.PartOfConnectionString("Data Source=", this.ConnectionString);

            }
        }

        public String Password
        {
            get
            {
                return this.PartOfConnectionString("Password=", this.ConnectionString);

            }
        }

        public String UserName
        {
            get
            {
                return this.PartOfConnectionString("User ID=", this.ConnectionString);
            }
        }


        public String Secret
        {
            get
            {
                return this.PartOfConnectionString("Secret=", this.ConnectionString);
            }
        }
        public String Port
        {
            get
            {
                return this.PartOfConnectionString("Port=", this.ConnectionString);
            }
        }

        public String PartOfConnectionString(string Name, string ConnectionString)
        {
            if (Name[Name.Length - 1] != '=')
            {
                Name += '=';
            }
            int s = ConnectionString.IndexOf(Name) + Name.Length;
            int e = ConnectionString.IndexOf(';', s + 1);
            if (e > 0)
            {
                return ConnectionString.Substring(s, e - s);
            }
            return ConnectionString.Substring(s);
        }

    }
}
